﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GTAHookAdv
{

    /// <summary>
    /// this class interact with some other classes from this micro API. You can here set some options.
    /// </summary>
    public class Core
    {

        private static TickRefreshFlag _tickrefreshoption = TickRefreshFlag.All;

        /// <summary>
        /// Set what to refresh when the core is ticked
        /// by default set to All (high CPU consuming, but good Cache)
        /// </summary>
        public static TickRefreshFlag TickRefreshOption
        {
            get { return Core._tickrefreshoption; }
            set { Core._tickrefreshoption = value; }
        }

        /// <summary>
        /// return true if <paramref name="flag"/> value has been setted to caches options.
        /// </summary>
        /// <param name="flag">choose one value from <see cref="TickRefreshFlag"/></param>
        /// <returns>true if choosen option has been setted</returns>
        /// <seealso cref="TickRefreshOptionAdd"/>
        /// <seealso cref="TickRefreshOptionRemove"/>
        public static bool IsTickRefreshOptionSetted(TickRefreshFlag flag)
        {
            return (_tickrefreshoption & flag) == flag;
        }

        /// <summary>
        /// Add an option to TickRefresh, this define witch caches are refreshed while core is ticked by your script.
        /// </summary>
        /// <param name="flag">option to add</param>
        /// /// <seealso cref="IsTickRefreshOptionSetted"/>
        /// <seealso cref="TickRefreshOptionRemove"/>
        public static void TickRefreshOptionAdd(TickRefreshFlag flag)
        {
            _tickrefreshoption = _tickrefreshoption | flag;
        }

        /// <summary>
        /// Remove an option from TickRefresh, this define witch caches are refreshed while core is ticked by your script.
        /// </summary>
        /// <param name="flag">option to add</param>
        /// /// <seealso cref="IsTickRefreshOptionSetted"/>
        /// <seealso cref="TickRefreshOptionRemove"/>
        public static void TickRefreshOptionRemove(TickRefreshFlag flag)
        {
            _tickrefreshoption = _tickrefreshoption &  ~flag;
        }

        private static bool _Ticked = false;

        /// <summary>
        /// Says if the Core has been ticked once.
        /// Many cache are initialized once core has been ticked.
        /// </summary>
        public static bool Ticked
        {
            get { return _Ticked; }
        }


        /// <summary>
        /// Callback to your script tick. So you choose how frequently caches are refreshed.
        /// </summary>
        public static void OnTick(object sender, EventArgs e)
        {
            _Ticked = true;
            if(IsTickRefreshOptionSetted(TickRefreshFlag.Blips))
                g_Blip.OnTick(sender,e);
        }
    }
}
